#include "EarParticleObject.h"
#include "catmullromcurveevaluator.h"

// hacks
#define COLOR_YELLOW	1.0f, 1.0f, 0.0f
#define COLOR_BROWN		0.647f, 0.176f, 0.176f
EarParticleObject::EarParticleObject(std::vector<Particle*> particles) {
	_particles = particles;
}

void EarParticleObject::render() {

	vector<Point> points[3];
	for (int i = 0; i < 3; i++) {
		CatmullRomCurveEvaluator curveEval;
		std::vector<Point> ptvCtrlPts;
		ptvCtrlPts.push_back(Point(0, _particles[0]->getPosition()[i]));
		ptvCtrlPts.push_back(Point(0.0001, _particles[0]->getPosition()[i]));
		ptvCtrlPts.push_back(Point(0.5, _particles[1]->getPosition()[i]));
		ptvCtrlPts.push_back(Point(1.0, _particles[2]->getPosition()[i]));
		curveEval.evaluateCurve(ptvCtrlPts, points[i], 1.0, false);
	}

	for (int i = 0; i < points[0].size(); i++) {
		glPushMatrix();
		if (i > 0.9 * points[0].size()) setDiffuseColor(COLOR_BROWN);
		else setDiffuseColor(COLOR_YELLOW);
		// Camera transform already applied before calling this...
		glTranslated(points[0][i].y,
			points[1][i].y,
			points[2][i].y);
		drawSphere(0.2); // just model as a sphere for now
		glPopMatrix();
		setDiffuseColor(COLOR_YELLOW);
	}

	/*
	for (std::vector<Particle*>::iterator i = _particles.begin(); i != _particles.end(); i++) {

		glPushMatrix();
		if (i == _particles.begin()) setDiffuseColor(COLOR_BROWN);
		else setDiffuseColor(COLOR_YELLOW);
		// Camera transform already applied before calling this...
		glTranslated((*i)->getPosition()[0], (*i)->getPosition()[1], (*i)->getPosition()[2]);
		drawSphere(0.2); // just model as a sphere for now
		glPopMatrix();
	}*/

}